package com.neusoft.care.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.neusoft.care.dto.ClientCareItemDto;
import com.neusoft.care.po.ClientCareItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ClientCareItemDao extends BaseMapper<ClientCareItem> {
    // 在这里可以定义一些自定义的SQL操作（如果有需要）
//    联合护理项目表和客户具有的护理项目表查询
    @Select("<script><![CDATA[" +
            "SELECT cci.item_id, cci.client_id, ci.item_name, ci.price, ci.cycle, ci.times, " +
            "       cci.quantity, " +
            "       CASE " +
            "           WHEN cci.quantity <= 0 THEN '欠费' " +
            "           ELSE '正常' " +
            "       END AS quantity_status, " +
            "       CASE " +
            "           WHEN cci.expire_date < CURDATE() THEN '到期' " +
            "           ELSE '未到期' " +
            "       END AS time_status " +
            "FROM client_care_items cci " +
            "JOIN care_items ci ON cci.item_id = ci.item_id " +
            "LEFT JOIN care_levels cl ON cci.level_id = cl.level_id " +
            "WHERE cci.client_id = #{clientId} " +
            "]]></script>")
    List<ClientCareItemDto> getClientCareItemsByClientId(@Param("clientId") Integer clientId);
}